package com.lsf.modules.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lsf.modules.system.entity.Reply;
import com.lsf.modules.system.entity.User;
import com.lsf.modules.system.service.ReplyService;
import com.lsf.modules.system.mapper.ReplyMapper;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Set;


/**
 * 回帖
 *
 * @author Alexander
 */
@Service
public class ReplyServiceImpl extends ServiceImpl<ReplyMapper, Reply> implements ReplyService {


    @Override
    public int vote(Reply reply, User user) {
        String goodIds = reply.getGoodIds();
        Set<String> strings = StringUtils.commaDelimitedListToSet(goodIds);
        if (strings.contains(user.getId())) {
            strings.remove(user.getId());
        } else {
            strings.add(user.getId());
        }
        reply.setGoodIds((StringUtils.collectionToCommaDelimitedString(strings)));
        reply.setGoodCount(strings.size());
        this.updateById(reply);
        return strings.size();
    }
}




